package com.liurong.netty.sync;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

public class SyncFutureTest {
	private final static Map<Integer, SyncFuture<String>> map = new ConcurrentHashMap<Integer, SyncFuture<String>>();

	public static void main(String[] args) throws Exception {
		new Thread() {
			@Override
			public void run() {
				SyncFuture<String> syncFuture = new SyncFuture<String>();
				map.put(1, syncFuture);
				try {
					String value = syncFuture.get(2, TimeUnit.SECONDS);
					System.out.println(value);
				} catch (InterruptedException e) {
					map.remove(1);
					e.printStackTrace();
				}
			}
		}.start();

		TimeUnit.SECONDS.sleep(1);

		SyncFuture<String> syncFuture = map.remove(1);
		syncFuture.setResponse("我的第一个同步调用");
	}
}
